package com.ruoyi.oss.factory;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.oss.template.MinioTemplate;
import com.ruoyi.oss.template.OssTemplate;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;

public class MinioOssFactory implements AbstractOssFactory {

    final private String endpoint ;
    final private String accessKey ;
    final private String secretKey ;

    public MinioOssFactory(String endpoint, String accessKey, String secretKey) {
        this.endpoint = endpoint;
        this.accessKey = accessKey;
        this.secretKey = secretKey;
    }

    @Override
    public OssTemplate createClient() {
        try {
            return new MinioTemplate(new MinioClient(endpoint,accessKey, secretKey));
        } catch (InvalidEndpointException e) {
            throw new ServiceException("OSS地址不正确");
        } catch (InvalidPortException e) {
            throw new ServiceException("OSS端口不正确");
        }
    }

}
